package com.dldata.display.control.pages;

import com.dldata.base.businessmodel.SessionUserInfoEntity;
import com.dldata.base.utils.Public;
import com.dldata.base.utils.RightUtil;
import com.dldata.display.utils.MD5Util;
import com.dldata.display.utils.Util;
import net.sf.json.JSONObject;
import org.json.JSONArray;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by 吴岳峰 on 2018-06-05.
 */
@Controller
@RequestMapping("/toQywx")
public class V_qywxController {
    @RequestMapping("/toIndex")
    public String toIndex(@RequestParam Map<String, Object> paramMap,Model model){
        model.addAttribute("paramMap",paramMap);
        return "/qywx/index";
    }

    @RequestMapping("/toList")
    public String toList(@RequestParam Map<String, Object> paramMap,Model model){
        model.addAttribute("paramMap",paramMap);
        return "/qywx/list";
    }

    @RequestMapping("/toKpibiao")
    public String toKpibiao(@RequestParam Map<String, Object> paramMap, Model model, HttpServletRequest request){
        String[] biIds = paramMap.get("biids").toString().split(",");
        String hbiName = Public.sysConfig.getProperty("hospitalName","");
        SessionUserInfoEntity sessionUserInfoEntity = RightUtil.getCurrentUser(request);
        String lName = sessionUserInfoEntity.getLname() ;
        for (String id : biIds) {
            String softKey = GetHBIParam(id,lName,hbiName);
            paramMap.put(id,softKey);
        }
        paramMap.put("biIp",Public.sysConfig.getProperty("HBIURL",""));
        paramMap.put("biqtuser",lName);
        JSONObject jsonObject = JSONObject.fromObject(paramMap);
        model.addAttribute("paramMap",jsonObject);
        return "/qywx/kpibiao";
    }

    @RequestMapping("/toGhxqfx")
    public String toGhxqfx(@RequestParam Map<String, Object> paramMap, Model model, HttpServletRequest request){
        String[] biIds = paramMap.get("biids").toString().split(",");
        String hbiName = Public.sysConfig.getProperty("hospitalName","");
        SessionUserInfoEntity sessionUserInfoEntity = RightUtil.getCurrentUser(request);
        String lName = sessionUserInfoEntity.getLname() ;
        for (String id : biIds) {
            String softKey = GetHBIParam(id,lName,hbiName);
            paramMap.put(id,softKey);
        }
        paramMap.put("biIp",Public.sysConfig.getProperty("HBIURL",""));
        paramMap.put("biqtuser",lName);
        JSONObject jsonObject = JSONObject.fromObject(paramMap);
        model.addAttribute("paramMap",jsonObject);
        return "/qywx/ghxqfx";
    }

    @RequestMapping("/toZyjb")
    public String toZyjb(@RequestParam Map<String, Object> paramMap, Model model, HttpServletRequest request){
        String[] biIds = paramMap.get("biids").toString().split(",");
        String hbiName = Public.sysConfig.getProperty("hospitalName","");
        SessionUserInfoEntity sessionUserInfoEntity = RightUtil.getCurrentUser(request);
        String lName = sessionUserInfoEntity.getLname() ;
        for (String id : biIds) {
            String softKey = GetHBIParam(id,lName,hbiName);
            paramMap.put(id,softKey);
        }
        paramMap.put("biIp",Public.sysConfig.getProperty("HBIURL",""));
        paramMap.put("biqtuser",lName);
        JSONObject jsonObject = JSONObject.fromObject(paramMap);
        model.addAttribute("paramMap",jsonObject);
        return "/qywx/zyjb";
    }

    @RequestMapping("/toBaobiao")
    public String toBaobiao(@RequestParam Map<String, Object> paramMap, Model model, HttpServletRequest request){
        String[] biIds = paramMap.get("biids").toString().split(",");
        String hbiName = Public.sysConfig.getProperty("hospitalName","");
        SessionUserInfoEntity sessionUserInfoEntity = RightUtil.getCurrentUser(request);
        String lName = sessionUserInfoEntity.getLname() ;
        for (String id : biIds) {
            String softKey = GetHBIParam(id,lName,hbiName);
            paramMap.put(id,softKey);
        }
        paramMap.put("biIp",Public.sysConfig.getProperty("HBIURL",""));
        paramMap.put("biqtuser",lName);
        JSONObject jsonObject = JSONObject.fromObject(paramMap);
        model.addAttribute("paramMap",jsonObject);
        return "/qywx/baobiao";
    }

    public String GetHBIParam(String strRptGID,String loginName,String hbiName){

        String HBIRegUnitName = hbiName;

        String str = "";

        Date newdate = new Date();
        SimpleDateFormat df=new SimpleDateFormat("yyyyMMdd");
        df.format(newdate.getTime());
        str = loginName + "longWebHBI" + strRptGID.toUpperCase() + df.format(newdate.getTime()) + HBIRegUnitName;


        String s= MD5Util.MD5Encoder(str);
        String s1 = MD5Util.MD5Encoder(str).toLowerCase();
        String s2 = MD5Util.MD5Encoder(s1);
        String ss = MD5Util.MD5Encoder(s1).toUpperCase();
        return MD5Util.MD5Encoder(MD5Util.MD5Encoder(str).toLowerCase()).toUpperCase();
    }
}
